package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-10-11
 * Time: 20:33
 */

public class Demo5 {
    private static boolean isFinished = false;//通过一标志来结束线程

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{

            while (!isFinished){
                System.out.println("hello thread");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            System.out.println("thread 结束");
        });

        t.start();
        Thread.sleep(3000);
        isFinished = true;
    }
}
